import { Injectable } from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { RequestService } from './request.service';
import { LocalStorageService } from './local-storage.service';
import { Router } from '@angular/router';
@Injectable({
  providedIn: 'root'
})
export class LoginService {
//   private baseUrl = 'http://localhost:8080/api/';
//   headers = new HttpHeaders();
//   getHeaders():HttpHeaders {
//       let headers = new HttpHeaders();
      
//       headers.append('Access-Control-Allow-Origin' , '*');
//       headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
//       headers.append('Accept','application/json');
//       headers.append('content-type','application/json');
//       return headers;
//   }

  constructor(
      private http: HttpClient,
      private requestService: RequestService,
      private storage: LocalStorageService,
      private router: Router
  ) {}

  login(username:string,password:string):Observable<any> {
    return  this.requestService.post('login', {username:username, password:password});
  }

  logout() {
    this.storage.remove('currentUser');
    this.router.navigateByUrl('login');
  }
}
